﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace SimpleLiteForm
{
    class KeyPoint
    {
        private Button _button;
        private PictureBox _pictureDisplay;
        private Presentation _presentation;
        private Bitmap _screenshotBmp;
        private int _index;
        private Screenshot _screenshot;

        public KeyPoint(Presentation presentation, int index, ProgressBar timeBar, PictureBox pictureDisplay)
        {
            _presentation = presentation;
            _pictureDisplay = pictureDisplay;
            _index = index;
            _screenshot = presentation.getScreenshot(index);

            initialize(timeBar, pictureDisplay);
        }

        private void initialize(ProgressBar timeBar, PictureBox pictureDisplay)
        {
            this._button = new Button();
            timeBar.Controls.Add(_button);

            this._button.BackColor = System.Drawing.SystemColors.HotTrack;

            TimeSpan time = _screenshot.time - _presentation.getBeginTime();
            double pt = (double)_presentation.getTimeSpan().TotalSeconds;
            float ratio = (float)time.TotalSeconds/(float)_presentation.getTimeSpan().TotalSeconds;
            int offset = (int)(timeBar.Width * ratio);
            this._button.Location = new System.Drawing.Point(offset, 0);

            this._button.Name = "button";
            this._button.Size = new System.Drawing.Size(timeBar.Height, timeBar.Height);
            this._button.TabIndex = 7;
            this._button.UseVisualStyleBackColor = false;
            this._button.Click += new System.EventHandler(this.button_Click);


        }

        private void button_Click(object sender, EventArgs e)
        {
            if(_screenshotBmp == null)
            {
                _screenshotBmp = new Bitmap(_screenshot.path);
            }
            _pictureDisplay.Image = (Image)_screenshotBmp;
            _pictureDisplay.SizeMode = PictureBoxSizeMode.StretchImage;
                
        }

        public void dispose()
        {
            _button.Dispose();
        }
    }
}
